<%--
  Created by IntelliJ IDEA.
  User: 31921
  Date: 2024/12/15
  Time: 14:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" language="java"
pageEncoding="UTF-8" %>
<%@ page import="java.util.*,com.Student" %>
<html>
    <head>
        <title>学生管理</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                background-color: #f4f4f4;
                margin: 0;
                padding: 0;
            }
            .header {
                background-color: #4cafa7;
                color: white;
                padding: 15px;
                text-align: center;
            }
            .container {
                padding: 20px;
            }
            table {
                width: 100%;
                border-collapse: collapse;
                margin-top: 20px;
            }
            table, th, td {
                border: 1px solid #ddd;
            }
            th, td {
                padding: 10px;
                text-align: left;
            }
            th {
                background-color: #f2f2f2;
            }
            .button {
                background-color: #afaa4c;
                color: white;
                padding: 10px 15px;
                text-decoration: none;
                margin-top: 10px;
                border-radius: 4px;
            }
            .button:hover {
                background-color: #a06045;
            }
            .search {
                margin-bottom: 20px;
            }
            .back-button {
                background-color: #4c89af;
                color: white;
                padding: 10px 15px;
                text-decoration: none;
                border-radius: 4px;
                margin-top: 20px;
                display: inline-block;
            }
            .back-button:hover {
                background-color: #a06045;
            }
        </style>
    </head>
    <body>

        <!-- 头部 -->
        <div class="header">
            <h1>学生管理系统</h1>
        </div>

        <!-- 与顶部隔开区域 -->
        <div class="container">

            <!-- 返回首页按钮 -->
            <a href="home.jsp" class="back-button">返回</a>

            <!-- 搜索栏 -->
            <div class="search">
                <form action="studentManagement" method="get">
                    <input type="text" name="search" placeholder="搜索学号或姓名"
                           value="<%= request.getParameter("search") != null ? request.getParameter("search") : "" %>" />
                    <button type="submit" class="button">搜索</button>
                </form>
            </div>

            <!-- 新增学生按钮 -->
            <a href="addStudent.jsp" class="button">新增学生</a>

            <!-- 学生列表 -->
            <table>
                <thead>
                <tr>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>邮箱</th>
                    <th>电话</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <%
                    List<Student> students = (List<Student>) request.getAttribute("students");
                    if (students != null) {
                        for (Student student : students) {
                %>
                <tr>
                    <td><%= student.getStudentId() %></td>
                    <td><%= student.getName() %></td>
                    <td><%= student.getGender() %></td>
                    <td><%= student.getAge() %></td>
                    <td><%= student.getEmail() %></td>
                    <td><%= student.getPhone() %></td>
                    <td>
                        <a href="editStudent?id=<%= student.getId() %>" class="button">编辑</a>
                        <a href="studentManagement?action=delete&id=<%= student.getId() %>" class="button">删除</a>
                    </td>
                </tr>
                <%
                        }
                    }
                %>
                </tbody>
            </table>

            <div class="pagination">
                <%
                    int currentPage = Integer.parseInt(request.getParameter("page") == null ? "1" : request.getParameter("page"));
                    Integer totalPages = (Integer) request.getAttribute("totalPages");

                    if (totalPages == null) {
                        totalPages = 1;  // 如果没有传递分页总数，设置为1
                    }

                    if (totalPages > 1) {
                %>
                <ul>
                    <li><a href="?page=1">首页</a></li>
                    <li><a href="?page=<%= currentPage - 1 > 0 ? currentPage - 1 : 1 %>">上一页</a></li>
                    <li><a href="?page=<%= currentPage + 1 <= totalPages ? currentPage + 1 : totalPages %>">下一页</a></li>
                    <li><a href="?page=<%= totalPages %>">尾页</a></li>
                </ul>
                <% } %>
            </div>

        </div>

    </body>
</html>


